package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.conn.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

    @Autowired
    private TrackInfoService trackInfoService;

    // /api/album/trackInfo/uploadTrack
    //上传声音
    @GuiGuLogin
    @PostMapping("/uploadTrack")
    public Result<UploadTrackVo> uploadTrack(MultipartFile file) {
        UploadTrackVo uploadTrackVo = trackInfoService.uploadTrack(file);
        return Result.ok(uploadTrackVo);
    }

    // /api/album/trackInfo/saveTrackInfo
    //新增声音
    @GuiGuLogin
    @PostMapping("/saveTrackInfo")
    public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo) {
        trackInfoService.saveTrackInfo(trackInfoVo);
        return Result.ok();
    }

    // /api/album/trackInfo/findUserTrackPage/{page}/{limit}
    // 获取当前用户声音分页列表
    @GuiGuLogin
    @PostMapping("/findUserTrackPage/{page}/{limit}")
    public Result<IPage<TrackListVo>> findUserTrackPage(
            @PathVariable Long page,
            @PathVariable Long limit,
            @RequestBody TrackInfoQuery trackInfoQuery) {
        IPage<TrackListVo> iPage = trackInfoService.findUserTrackPage(page, limit, trackInfoQuery);
        return Result.ok(iPage);
    }

    // /api/album/trackInfo/getTrackInfo/{id}
    // 根据id查询声音信息
    @GuiGuLogin
    @GetMapping("/getTrackInfo/{id}")
    public Result<TrackInfo> getTrackInfo(@PathVariable Long id) {
        TrackInfo trackInfo = trackInfoService.getTrackInfoById(id);
        return Result.ok(trackInfo);
    }

    // /api/album/trackInfo/updateTrackInfo/{id}
    // 修改声音信息
    @GuiGuLogin
    @PutMapping("/updateTrackInfo/{id}")
    public Result updateTrackInfo(@PathVariable Long id, @RequestBody TrackInfoVo trackInfoVo) {
        trackInfoService.updateTrackInfo(id, trackInfoVo);
        return Result.ok();
    }

    // /api/album/trackInfo/removeTrackInfo/{id}
    // 删除声音
    @GuiGuLogin
    @DeleteMapping("/deleteTrackInfo/{id}")
    public Result deleteTrackInfo(@PathVariable Long id) {
        trackInfoService.deleteTrackInfo(id);
        return Result.ok();
    }

    // /api/album/trackInfo/findAlbumTrackPage/{albumId}/{page}/{limit}
    //获取专辑声音分页列表
    @GuiGuLogin
    @GetMapping("/findAlbumTrackPage/{albumId}/{page}/{limit}")
    public Result<IPage<AlbumTrackListVo>> findAlbumTrackPage(
            @PathVariable Long albumId,
            @PathVariable Long page,
            @PathVariable Long limit) {
        IPage<AlbumTrackListVo> iPage = trackInfoService.findAlbumTrackPage(albumId, limit, page);
        return Result.ok(iPage);
    }

    // /api/album/trackInfo/getTrackStatVo/{trackId}
    //获取声音统计信息
    @GetMapping("/getTrackStatVo/{trackId}")
    public Result<TrackStatVo> getTrackStatVo(@PathVariable Long trackId) {
        TrackStatVo trackStatVo = trackInfoService.getTrackStatVo(trackId);
        return Result.ok(trackStatVo);
    }

    // /api/album/trackInfo/findUserTrackPaidList/{trackId}
    //获取用户声音分集购买支付列表
    @GuiGuLogin
    @GetMapping("/findUserTrackPaidList/{trackId}")
    public Result<List<TrackPayVo>> findUserTrackPaidList(@PathVariable Long trackId) {
        List<TrackPayVo> trackPayVos = trackInfoService.findUserTrackPaidList(trackId);
        return Result.ok(trackPayVos);
    }
    // 获取用户要购买的声音的列表
    @GetMapping(value = "/findPaidTrackInfoList/{trackId}/{trackCount}")
    public Result<List<TrackInfo>> findPaidTrackInfoList(@PathVariable(value = "trackId") Long trackId , @PathVariable(value = "trackCount") Integer trackCount) {
        List<TrackInfo> list = trackInfoService.findPaidTrackInfoList(trackId , trackCount) ;
        return Result.ok(list) ;
    }
}

